package com.tanxi521.springboot.controller;

import com.tanxi521.springboot.pojo.APIResult;
import com.tanxi521.springboot.pojo.Code;
import com.tanxi521.springboot.utils.FileUploadUtils;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/file")
@CrossOrigin
public class FileUploadController {

    @PostMapping("/upload")
    public APIResult fileUpload(MultipartFile file) {
        String viewPath = FileUploadUtils.uploadHeadImg(file);
        if (viewPath.equals("500")) {
            return new APIResult(APIResult.FAIL, "文件上传失败");
        } else {
            return new APIResult(viewPath, APIResult.SUCCESS, "文件上传成功");
        }
    }
}
